//
// Created by mio on 25-5-9.
//

#include "LoginServer.h"

#include "LoginConnection.h"
#include "../Net/EventLoop.h"

LoginServer::LoginServer(EventLoop* eventloop) : TcpServer(eventloop), loop_(eventloop), client_(nullptr)
{
    client_.reset(new TcpClient());
    client_->Create();
    if (client_->Connect("127.0.0.1", 8523))
    {
        client_->GetMonitorInfo();
        id_ = loop_->AddTimer([this]()
        {
            client_->GetMonitorInfo();
            return true;
        }, 1000);
    }
}

LoginServer::~LoginServer()
{

}

std::shared_ptr<LoginServer> LoginServer::Create(EventLoop* eventloop)
{
    std::shared_ptr<LoginServer> server(new LoginServer(eventloop));
    return server;
}


TcpConnectionPtr LoginServer::OnConnect(int fd)
{
    return std::make_shared<LoginConnection>(loop_->GetTaskScheduler().get(), fd);
}
